/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement = function (nums) {
  let n = nums.length;
  let average = n / 2;
  let hashMap = {};
  for (let i = 0; i < n; i++) {
    if (!hashMap[nums[i]]) {
      hashMap[nums[i]] = 1;
    } else {
      hashMap[nums[i]]++;
    }
  }
  if (hashMap[nums[i]] > average) return nums[i];
};
